<template>
    <el-dialog v-model="show" title="客户福利采购申请" width="20%" align-center @close="handleClose">
        <el-row>
            <el-col class="flex" :span="24">
                <div class="label">
                    产品名称：
                </div>
                <div>{{ props.initList.welfareName }}</div>
            </el-col>
            <el-col class="flex" :span="24">
                <div class="label">
                    申请采购数量：
                </div>
                <div>{{ props.initList.applyNumber }}</div>
            </el-col>
            <el-col class="flex" :span="24">
                <div class="label">
                    申请采购单价：
                </div>
                <div>{{ props.initList.price }}</div>
            </el-col>
            <el-col class="flex" :span="24">
                <div class="label">
                    申请采购总价：
                </div>
                <div>{{ Number(props.initList.price) * Number(props.initList.applyNumber) }}</div>
            </el-col>
            <el-col class="flex" :span="24">
                <div class="label">
                    采购申请备注：
                </div>
                <div>{{ props.initList.remark }}</div>
            </el-col>
        </el-row>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="handleRefuse">拒 绝</el-button>
                <el-button type="primary" @click="handleSubmit()">通 过</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { approvalApi } from '@/api/sj/purchaseManagement/welfareProcurement/index'

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const props = defineProps(['visible', 'initList']);
const emits = defineEmits(['submit', 'close']);

const show = ref(false);

watch(() => props.visible, async (newValue) => {
    show.value = newValue
    if (newValue) {
    }
}, { deep: true });

const handleSubmit = async () => {
    approval(2)
};

const handleClose = () => {
    emits('close');

};

const handleRefuse = async () => {
    approval(3)
};

const approval = async (approvalStatus: number) => {
    const { code } = await approvalApi({
        id: props.initList.id,
        approvalStatus
    })
    if (code === 200) {
        proxy?.$modal.msgSuccess('操作成功');
        emits('submit', true);
        handleClose()
    }
};

onMounted(() => {
})
</script>

<style lang="scss" scoped>
.label {
    height: 32px;
    line-height: 32px;
    font-weight: 700;
    display: inline-flex;
    justify-content: flex-end;
    align-items: flex-start;
    padding: 0 12px 0 0;
    box-sizing: border-box;
    flex: 0 0 auto;
    font-size: var(--el-form-label-font-size);
    color: var(--el-text-color-regular);
    width: 130px;
}

.flex {
    display: flex;
    align-items: center;
}
</style>